﻿#region changelog
/*
 * 11/22/11 - as (Prodigy Software Ltd): Original code
*/
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Compression;

namespace Durrant.Plugins
{
    public class CompressionHelper
    {
        public static MemoryStream decompressGZipStream(Stream stream)
        {
            MemoryStream memoryStream = new MemoryStream();
            byte[] readBuffer = new byte[4096];
            // decompress the webResponseStream to a memoryStream
            using (GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress))
            {
                int i;
                while ((i = gzipStream.Read(readBuffer, 0, readBuffer.Length)) != 0)
                {
                    memoryStream.Write(readBuffer, 0, i);
                }
                memoryStream.Seek(0, SeekOrigin.Begin);
            }
            return memoryStream;
        }
    }
}
